package com.my9yu.common.socket.codec.json;

import java.nio.charset.Charset;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;

import com.my9yu.common.socket.core.Message;
import com.my9yu.common.socket.util.JsonUtils;

public class JsonDecoder implements ProtocolDecoder {

	public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
		String content = in.getString(Charset.forName("UTF-8").newDecoder());
		Object body = JsonUtils.string2Object(content, Message.class);
		out.write(body);

	}

	public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception {

	}

	public void dispose(IoSession session) throws Exception {

	}

}
